<HTML>
<HEAD>
<TITLE>[Chapter 10] 10.3 MenuShortcut</TITLE>
<META NAME="author" CONTENT="John Zukowski">
<META NAME="date" CONTENT="Thu Jul 31 14:46:15 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java AWT">
<META NAME="title" CONTENT="Java AWT">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java AWT" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch10_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 10<br>Would You Like to Choose from the Menu?</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch10_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JAWT-CH-10-SECT-3">10.3 MenuShortcut</A></h2>

<P CLASS=para>
<A NAME="CH10.SHORT1"></A><A NAME="CH10.SHORT2"></A><A NAME="CH10.SHORT3"></A><tt CLASS=literal>MenuShortcut</tt> is a class used to represent a keyboard shortcut for a <tt CLASS=literal>MenuItem</tt>. 
When these events occur, an action event is generated that triggers the 
menu component. When a shortcut is associated with a <tt CLASS=literal>MenuItem</tt>, 
the <tt CLASS=literal>MenuItem</tt> automatically 
displays a visual clue, which indicates that a keyboard accelerator is available. 

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-10-SECT-3.1">MenuShortcut Methods</A></h3>Constructors

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public MenuShortcut (int key) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The first <tt CLASS=literal>MenuShortcut</tt> constructor 
creates a <tt CLASS=literal>MenuShortcut</tt> with 
<tt CLASS=literal>key</tt> as its designated hot key. 
The <tt CLASS=literal>key</tt> parameter can be any of the virtual key codes from the <tt CLASS=literal>KeyEvent</tt> class (e.g., <tt CLASS=literal>VK_A</tt>, <tt CLASS=literal>VK_B</tt>, etc.). These constants are listed in <A HREF="ch04_03.htm#JAWT-CH-4-TAB-4">Table 4.4</A>. To use the shortcut, the user must combine the given <tt CLASS=literal>key</tt> 
with a platform-specific modifier key. On Windows and Motif platforms, 
the modifier is the Control key; on the Macintosh, it is the Command key. 
For example, if the shortcut key is F1 (<tt CLASS=literal>VK_F1</tt>) and you're using Windows, 
you would press Ctrl+F1 to execute the shortcut. To find out the platform's 
modifier key, call the <tt CLASS=literal>Toolkit.getMenuShortcutKeyMask()</tt> method. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public MenuShortcut(int key, boolean useShiftModifier) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
This <tt CLASS=literal>MenuShortcut</tt> constructor 
creates a <tt CLASS=literal>MenuShortcut</tt> with 
<tt CLASS=literal>key</tt> as its designated hot key. 
If <tt CLASS=literal>useShiftModifier</tt> is <tt CLASS=literal>true</tt>, 
the Shift key must be depressed for this shortcut to trigger the action 
event (in addition to the shortcut key). The <tt CLASS=literal>key</tt> 
parameter represents the integer value of a <tt CLASS=literal>KEY_PRESS</tt> 
event, so in addition to ASCII values, possible values include the various 
<tt CLASS=literal>Event</tt> keyboard constants (listed in <A HREF="ch04_02.htm#JAWT-CH-4-TAB-2">Table 4.2</A>) like <tt CLASS=literal>Event.F1</tt>, 
<tt CLASS=literal>Event.HOME</tt>, and <tt CLASS=literal>Event.PAUSE</tt>. 
For example, if <tt CLASS=literal>key</tt> is the 
ASCII value for A and <tt CLASS=literal>useShiftModifier</tt> 
is <tt CLASS=literal>true</tt>, the shortcut key is 
Shift+Ctrl+A on a Windows/Motif platform. </DL>
Miscellaneous methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getKey () <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getKey()</tt> method retrieves 
the virtual key code for the key that triggered this <tt CLASS=literal>MenuShortcut</tt>. The virtual key codes are the <tt CLASS=literal>VK</tt> constants defined by the <tt CLASS=literal>KeyEvent</tt> class (see <A HREF="ch04_03.htm#JAWT-CH-4-TAB-4">Table 4.4</A>).

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public boolean usesShiftModifier() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>usesShiftModifier()</tt> method 
returns <tt CLASS=literal>true</tt> if this <tt CLASS=literal>MenuShortcut</tt> 
requires the Shift key be pressed, <tt CLASS=literal>false</tt> 
otherwise. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public boolean equals(MenuShortcut s) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>equals()</tt> method overrides 
<tt CLASS=literal>Object</tt>'s <tt CLASS=literal>equals()</tt> 
method to define equality for menu shortcuts. Two <tt CLASS=literal>MenuShortcut</tt> 
objects are equal if their <tt CLASS=literal>key</tt> 
and <tt CLASS=literal>useShiftModifier</tt> values 
are equal. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>protected String paramString () <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>paramString()</tt> method of 
<tt CLASS=literal>MenuShortcut</tt> helps build up 
a string describing the shortcut; it appends the shortcut key and a shift 
modifier indicator to the string under construction. Oddly, this method 
is not currently used, nor can you call it; <tt CLASS=literal>MenuShortcut</tt> 
has its own <tt CLASS=literal>toString()</tt> method 
that does the job itself. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>public String toString() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>toString()</tt> method of <tt CLASS=literal>MenuShortcut</tt> 
builds a <tt CLASS=literal>String</tt> to display 
the contents of the <tt CLASS=literal>MenuShortcut</tt>. </DL>
</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch10_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch10_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>MenuContainer</td>
<td width=171 align=center valign=top><a href="index/idx_a.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>MenuItem</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
